/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			plugin.h
  \date			May 2012
  \author		TNick

  \brief		Contains the definition for PlugIn class


*//*

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PLUGIN_INC__
#define __PLUGIN_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<cpg/cpg.h>
#include	<cpg/cpglibrary.h>

#include	<QObject>
#include	<QList>
#include	<QString>
#include	<QDir>
#include	<memtrack.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/* following macro (PLUGIN_BUILD) should be defined with DEFINES += PLUGIN_BUILD
in the project for the plug-in */
#if defined(DE_PLUGIN_BUILD)
#  define PLGIN_EXPORT Q_DECL_EXPORT
#else
#  define PLGIN_EXPORT Q_DECL_IMPORT
#endif



class	QToolBar;
class	QMenu;


namespace	BBlocks		{

class	UserMsg;

}


namespace	cpg	{


namespace	PlugIns	{

/**
*	@brief	class representing a (file based) plug-in loaded in memory
*/
class CPGSHARED_EXPORT PlugIn		: public MemTrack		{
	BBM_TRACK( PlugIn );

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	friend class PlgInMan;

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:


	/**
	*	@brief	associated file
	*/
	QString								file_;


protected:


	/**
	*	@brief	name of plug-in
	*/
	QString								name_;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


	/**
	*	@brief	constructor;
	*/
	PlugIn				( void );


	/**
	*	@brief	destructor;
	*/
	virtual				~PlugIn			( void );


	/**
	*	@brief	this function is called after the parent finished
	*	initialization procedures
	*
	*	Notably, the file name is set inside the instance when
	*	before the call is performed.
	*/
	virtual bool		initComplete	( BBlocks::UserMsg & um );


	/**
	*	@brief	called just before Plug-in system is stopped
	*
	*	The plug-ins recieve this call from PlgInMan::systemClosing().
	*	The plug-in pointer will then be unloaded and deleted,
	*	so implementation is capable of clean-ups in destructor.
	*
	*	Default implementation does nothing;
	*/
	virtual void		systemClosing	( BBlocks::UserMsg & um );


	/**
	*	@brief	allows plug-ins to alter contextual menu for a view
	*/
	virtual void		customiseViewMenu (
			QMenu *					menu
			) { Q_UNUSED( menu ); }


	/**
	*	@brief	get name
	*/
	inline QString		name			( void ) const
	{ return name_; }


	/**
	*	@brief	get the file that produced this plug-in
	*/
	inline QString		file			( void ) const
	{ return file_; }


protected:


	/**
	*	@brief	set name
	*/
	inline void			setName			( const QString & new_val )
	{
		name_ = new_val;
	}


	/**
	*	@brief	set the file that produced this plug-in
	*/
	inline void			setFile			( const QString & new_val )
	{
		file_ = QDir().absoluteFilePath( new_val );
		if ( name_.isEmpty() )
			name_ = CpgLibrary::lastPathComp( file_ );
	}


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class PlugIn	*/

}	//	namespace	PlugIns

}	//	namespace	cpg

/**
*	@brief	the type of the function we're looking for
*/
typedef	cpg::PlugIns::PlugIn *		(*GetPlyGrInterf)			(
		char *					p_version,
		BBlocks::UserMsg &		um
		);


#ifdef		__cplusplus
extern "C" {
#endif



/**
*	@brief	also define the name of the function to search (for QLibrary)
*/
#define	GET_INTERF_FUN			getPlugInInterface

/**
*	@brief	and the name as string
*/
#define	GET_INTERF_FUN_NAME		"getPlugInInterface"


#ifdef		__cplusplus
}
#endif


/*  CLASS    =============================================================== */
//
//
//
//

#endif // __PLUGIN_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
